<style>
    td:nth-child(2) {
        color: red;
    }
    td:nth-child(3) {
        color: green;
    }
    td:nth-child(4) {
        color: blue;
    }
</style>
<?php
// 1.获取连接
$conn = mysqli_connect("localhost:3306","root","","php");
// 2.执行sql
$sql = "select p_id id,p_name name,p_price price,p_unit unit,p_image image from t_product";
$result = mysqli_query($conn, $sql);
// var_dump($result);
// 3.处理结果
if($result){
    // 获取结果集中的数据
    echo "<table border='1' cellpadding='5' >";
    $num = mysqli_num_rows($result);
    for ($i=0; $i < $num; $i++) { 
        $row = mysqli_fetch_assoc($result);
        if($i == 0){
            echo "<tr>";
            foreach ($row as $key => $val) {
                echo "<td>$key</td>";
            }
            echo "</tr>";
        }
        echo "<tr>";
        foreach ($row as $key => $val) {
            if($key == "image"){
                echo "<td><img src='/day04/loadImage.php?p_id={$row['id']}' style='width:200px' /></td>";
            } else {
                echo "<td>$val</td>";
            }
            
        }
        echo "</tr>";
    }
    echo "</table>";
}
// 4.关闭连接
mysqli_close($conn);
?>